package com.baimifan.renovation.homefrag;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baimifan.renovation.R;
import com.baimifan.renovation.tools.CircleImageView;
import com.baimifan.renovation.tools.statusBar;

/**
 * 首页-我的
 */
public class MyFragment extends Fragment {
    private Float w, h, widthPixels, heightPixels;
    private FrameLayout my_fl;
    private CircleImageView header_iv;
    private TextView my_noLogin;
    private LinearLayout my_data_ll;
    private TextView name, phone;
    private RelativeLayout data_rtask;
    private ImageView iv_task;
    private TextView tv_task;
    private ImageView iv_tag1;
    private View my_viewTag;
    private RelativeLayout data_rmoney;
    private ImageView iv_money;
    private TextView tv_money;
    private TextView tv_balance;
    private ImageView iv_tag2;
    private View my_viewTag2;
    private RelativeLayout data_rdemo;
    private ImageView iv_demo;
    private TextView tv_demo;
    private ImageView iv_tag3;
    private View my_viewTag3;
    private RelativeLayout data_rmess;
    private ImageView iv_mess;
    private TextView tv_mess;
    private ImageView iv_tag4;
    private View my_viewTag4;
    private RelativeLayout data_rbuild;
    private ImageView iv_build;
    private TextView tv_build;
    private ImageView iv_tag5;
    private View my_viewTag5;
    private RelativeLayout data_rkf;
    private ImageView iv_kf;
    private TextView tv_kf;
    private ImageView iv_tag6;
    private View my_viewTag6;
    private RelativeLayout data_rset;
    private ImageView iv_set;
    private TextView tv_set;
    private ImageView iv_tag7;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        init(view);
        getDisplay();
        setLayoutParams();
        return view;
    }

    private void init (View view) {
        my_fl = (FrameLayout) view.findViewById(R.id.my_fl);
        header_iv = (CircleImageView) view.findViewById(R.id.my_header_iv);
        my_noLogin = (TextView) view.findViewById(R.id.my_noLogin);
        my_data_ll = (LinearLayout) view.findViewById(R.id.my_data_ll);
        name = (TextView) view.findViewById(R.id.my_name);
        phone = (TextView) view.findViewById(R.id.my_phone);
        data_rtask = (RelativeLayout) view.findViewById(R.id.my_data_rtask);
        tv_task = (TextView) view.findViewById(R.id.my_tv_task);
        iv_task = (ImageView) view.findViewById(R.id.my_iv_task);
        iv_tag1 = (ImageView) view.findViewById(R.id.my_iv_tag1);
        my_viewTag = view.findViewById(R.id.my_viewTag);
        data_rmoney = (RelativeLayout) view.findViewById(R.id.my_data_rmoney);
        iv_money = (ImageView) view.findViewById(R.id.my_iv_money);
        tv_money = (TextView) view.findViewById(R.id.my_tv_money);
        tv_balance = (TextView) view.findViewById(R.id.my_tv_balance);
        iv_tag2 = (ImageView) view.findViewById(R.id.my_iv_tag2);
        my_viewTag2 = view.findViewById(R.id.my_viewTag2);
        data_rdemo = (RelativeLayout) view.findViewById(R.id.my_data_rdemo);
        iv_demo = (ImageView) view.findViewById(R.id.my_iv_demo);
        tv_demo = (TextView) view.findViewById(R.id.my_tv_demo);
        iv_tag3 = (ImageView) view.findViewById(R.id.my_iv_tag3);
        my_viewTag3 = view.findViewById(R.id.my_viewTag3);
        data_rmess = (RelativeLayout) view.findViewById(R.id.my_data_rmess);
        iv_mess = (ImageView) view.findViewById(R.id.my_iv_mess);
        tv_mess = (TextView) view.findViewById(R.id.my_tv_mess);
        iv_tag4 = (ImageView) view.findViewById(R.id.my_iv_tag4);
        my_viewTag4 = view.findViewById(R.id.my_viewTag4);
        data_rbuild = (RelativeLayout) view.findViewById(R.id.my_data_rbuild);
        iv_build = (ImageView) view.findViewById(R.id.my_iv_build);
        tv_build = (TextView) view.findViewById(R.id.my_tv_build);
        iv_tag5 = (ImageView) view.findViewById(R.id.my_iv_tag5);
        my_viewTag5 = view.findViewById(R.id.my_viewTag5);
        data_rkf = (RelativeLayout) view.findViewById(R.id.my_data_rkf);
        iv_kf = (ImageView) view.findViewById(R.id.my_iv_kf);
        tv_kf = (TextView) view.findViewById(R.id.my_tv_kf);
        iv_tag6 = (ImageView) view.findViewById(R.id.my_iv_tag6);
        my_viewTag6 = view.findViewById(R.id.my_viewTag6);
        data_rset = (RelativeLayout) view.findViewById(R.id.my_data_rset);
        iv_set = (ImageView) view.findViewById(R.id.my_iv_set);
        tv_set = (TextView) view.findViewById(R.id.my_tv_set);
        iv_tag7 = (ImageView) view.findViewById(R.id.my_iv_tag7);
    }

    private void getDisplay() {
        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        widthPixels = Float.valueOf(metrics.widthPixels);
        heightPixels = Float.valueOf(metrics.heightPixels);
        w = widthPixels / 360;
        h = heightPixels / 640;
    }

    private void setLayoutParams () {
        LinearLayout.LayoutParams params_my_fl = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)(h*150));
        my_fl.setLayoutParams(params_my_fl);
        FrameLayout.LayoutParams params_header = new FrameLayout.LayoutParams((int)(56*w), (int)(56*h));
        params_header.gravity = Gravity.LEFT | Gravity.CENTER;
        params_header.setMargins((int)(w*15), 0, 0, 0);
        header_iv.setLayoutParams(params_header);
        FrameLayout.LayoutParams params_noLogin = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_noLogin.gravity = Gravity.LEFT | Gravity.CENTER;
        params_noLogin.setMargins((int)(w*86),0, 0, 0);
        my_noLogin.setPadding((int)(w*15), (int)(h*5), (int)(13*w), (int)(h*5));
        my_noLogin.setLayoutParams(params_noLogin);
        FrameLayout.LayoutParams params_data_ll = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_data_ll.gravity = Gravity.LEFT | Gravity.CENTER;
        params_data_ll.setMargins((int)(w*95),0, 0, 0);
        my_data_ll.setLayoutParams(params_data_ll);

        LinearLayout.LayoutParams params_r_task = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_r_task.setMargins(0, 6, 0, 0);
        data_rtask.setLayoutParams(params_r_task);
        params_r_task.setMargins(0, 0, 0, 0);
        data_rmoney.setLayoutParams(params_r_task);
        data_rdemo.setLayoutParams(params_r_task);
        data_rmess.setLayoutParams(params_r_task);
        data_rbuild.setLayoutParams(params_r_task);
        data_rkf.setLayoutParams(params_r_task);
        data_rset.setLayoutParams(params_r_task);

        RelativeLayout.LayoutParams params_iv = new RelativeLayout.LayoutParams((int)(w*25), (int)(h*25));
        params_iv.setMargins((int)(w*29), (int)(h*15), 0, (int)(h*14));
        params_iv.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_task.setLayoutParams(params_iv);

        RelativeLayout.LayoutParams params_iv2 = new RelativeLayout.LayoutParams((int)(w*25), (int)(h*22.4));
        params_iv2.setMargins((int)(w*29), (int)(h*15), 0, (int)(h*14.6));
        params_iv2.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_money.setLayoutParams(params_iv2);

        RelativeLayout.LayoutParams params_iv3 = new RelativeLayout.LayoutParams((int)(w*24), (int)(h*23.9));
        params_iv3.setMargins((int)(w*29), (int)(h*14), 0, (int)(h*15.1));
        params_iv3.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_demo.setLayoutParams(params_iv2);

        RelativeLayout.LayoutParams params_iv4 = new RelativeLayout.LayoutParams((int)(w*25), (int)(h*26.1));
        params_iv4.setMargins((int)(w*29), (int)(h*14), 0, (int)(h*14.9));
        params_iv4.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_mess.setLayoutParams(params_iv4);

        RelativeLayout.LayoutParams params_iv5 = new RelativeLayout.LayoutParams((int)(w*24), (int)(h*24.1));
        params_iv5.setMargins((int)(w*29), (int)(h*15), 0, (int)(h*14.9));
        params_iv5.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_build.setLayoutParams(params_iv5);

        RelativeLayout.LayoutParams params_iv6 = new RelativeLayout.LayoutParams((int)(w*26), (int)(h*25));
        params_iv6.setMargins((int)(w*29), (int)(h*14), 0, (int)(h*16));
        params_iv6.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_kf.setLayoutParams(params_iv6);

        RelativeLayout.LayoutParams params_iv7 = new RelativeLayout.LayoutParams((int)(w*25), (int)(h*25));
        params_iv7.setMargins((int)(w*29), (int)(h*14), 0, (int)(h*15));
        params_iv7.addRule(RelativeLayout.CENTER_VERTICAL);
        iv_set.setLayoutParams(params_iv7);

        RelativeLayout.LayoutParams params_tv = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params_tv.setMargins((int)(w*81), (int)(h*17), 0, (int)(h*16));
        params_tv.addRule(RelativeLayout.CENTER_VERTICAL);
        tv_task.setLayoutParams(params_tv);
        tv_money.setLayoutParams(params_tv);
        tv_demo.setLayoutParams(params_tv);
        tv_mess.setLayoutParams(params_tv);
        tv_build.setLayoutParams(params_tv);
        tv_kf.setLayoutParams(params_tv);
        RelativeLayout.LayoutParams params_tv2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params_tv2.setMargins((int)(w*81), (int)(h*17), 0, (int)(h*16));
        tv_set.setLayoutParams(params_tv2);

        RelativeLayout.LayoutParams params_balance = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params_balance.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params_balance.addRule(RelativeLayout.CENTER_VERTICAL);
        params_balance.rightMargin = (int)(w*37);
        tv_balance.setLayoutParams(params_balance);

        RelativeLayout.LayoutParams params_nexTtag = new RelativeLayout.LayoutParams((int)(w*10), (int)(h*15));
        params_nexTtag.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params_nexTtag.addRule(RelativeLayout.CENTER_VERTICAL);
        params_nexTtag.setMargins(0, (int)(h*19), (int)(w*12), (int)(h*21));
        iv_tag1.setLayoutParams(params_nexTtag);
        iv_tag2.setLayoutParams(params_nexTtag);
        iv_tag3.setLayoutParams(params_nexTtag);
        iv_tag4.setLayoutParams(params_nexTtag);
        iv_tag5.setLayoutParams(params_nexTtag);
        iv_tag6.setLayoutParams(params_nexTtag);
        iv_tag7.setLayoutParams(params_nexTtag);

        LinearLayout.LayoutParams params_tag = new LinearLayout.LayoutParams((int)(w*330), 2);
        params_tag.setMargins((int)(w*16), 0, 0 ,0);
        my_viewTag.setLayoutParams(params_tag);
        my_viewTag2.setLayoutParams(params_tag);
        my_viewTag3.setLayoutParams(params_tag);
        my_viewTag4.setLayoutParams(params_tag);
        my_viewTag5.setLayoutParams(params_tag);
        my_viewTag6.setLayoutParams(params_tag);
    }
}
